/**
 * 
 * @returns {Boolean}
 */
function save ()
{
	$('#form-arquivo').removeBlockMessages().blockMessage( 'Aguarde...', {type: 'loading'} );
	
	return true;
}

/**
 * 
 * @param iframe
 * @returns {Boolean}
 */
function callBackUpload ( iframe )
{
    var div = $(iframe).contents().find('div');
    
    if ( div.length ) {
    	var json = eval('(' + div.eq(0).html() + ')' );
    	
    	$('#form-arquivo').removeBlockMessages();
	
		$(json.description).each(
		    function ( index, value )
		    {
		    	$('#form-arquivo').blockMessage( value.message, {type: value.level} );
		    }
	    );
		
		if ( json.status ) {
			
			refreshView();
			
		} else {
			
		    if ( json.errors ) {
		    	showErrorsForm( json.errors );
		    	errorUpload('arquivo');
		    }
		    
		}
		
    }
    
    return true;
}

function deletar ()
{
	if ( confirm('Deseja realmente deletar?') ) {
		$.get(
			baseUrl + '/admin/arquivo/delete/', 
			function ( response ) 
			{
				refreshView();
			}
		);
	}
}

/**
 * 
 */
function abrir ()
{
	var option = {};
	
    option.title 	= 'Lista de Carros';
    option.url	 	= baseUrl + '/admin/arquivo/open';
    option.minWidth = 1024;

    showDialog( option );
}

function download ()
{
	var url = baseUrl + '/admin/arquivo/download';
	
	window.location.assign( url );
}

/**
 * 
 */
function refreshView ()
{
	$('#form-arquivo').parent().loadWithEffect(
		baseUrl + '/admin/arquivo/',
		function ()
		{
			$('.mini-menu').css({opacity: 1});
			layoutUpload();
		}
	);	
}